package com.chub.study.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

// 2）注解的启用
// Swagger2: @EnableSwagger2
// Swagger3: @EnableOpenApi
//
// 3）页面的位置
// Swagger2: http://localhost:8080/swagger-ui.html
// Swagger3: http://localhost:8080/swagger-ui/
// 注意：最后的斜杠不能省略



@Configuration
@EnableSwagger2
// @EnableOpenApi
public class SwaggerConfig {

    @Bean
    public Docket adminApiConfig(){


        ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder();
        ApiInfo apiInfo = apiInfoBuilder.title("运营系统API文档")
                .description("本丸当描述了谷粒学院运营系统API接口")
                .version("1.0")
                .contact(new Contact("Helen","http://baidu.com","123@qqcom"))
                .build();

        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        docket
                .groupName("adminApi")
                .select()
//                .paths(Predicates.and(PathSelectors.regex("/admin/.*")))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo);
        return docket;
    }
    @Bean
    public Docket apiApiConfig(){

        ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder();
        ApiInfo apiInfo = apiInfoBuilder.title("网站系统API文档")
                .description("本丸当描述了谷粒学院网站系统API接口")
                .version("1.0")
                .contact(new Contact("Helen","http://baidu.com","123@qqcom"))
                .build();

        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        docket
                .groupName("webApi")
                .select()
//                .paths(Predicates.and(PathSelectors.regex("/api/.*")))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo);
        return docket;
    }
}
